#pragma once

#include "..\\headers.default.h"
#include "..\\headers.cv.h"

#include "ipfe_base.h"
#include "ipfe_shape_pattern.h"
#include "ipfe_default_ipfc_set.h"

using namespace loirey;

class CImagePyramidPosition
{
public:
	double xScale, yScale;
	double xOld, yOld;
	double xNew, yNew;
public:
	void InitScale(double xOld, double yOld, double xNew, double yNew);
	void InitNew(double xOld, double yOld, double xScale, double yScale);
	void InitOld(double xNew, double yNew, double xScale, double yScale);

	bool operator < (const CImagePyramidPosition& AnotherInstance) const;

	bool InputFromStream(istream& inStream);
	void OutputToStream(ostream& outStream) const;

	//virtual size_t GetMemoryUsage() const;
};

class CImagePyramidPositionFeatureExtractor : public CSingleDataForClassification
{
public:
	int IPFE_Pool_Size;
	CSimpleTypeArray<CImagePositionFeatureExtractor*> IPFE_Pool_IPFE_List;
	int LayersUsedCount;
	int HistoryCount;
	CSimpleTypeArray<int> IPFE_Pool_History_List;
	CSimpleTypeArray<double> IPFE_Pool_xScale_List;
	CSimpleTypeArray<double> IPFE_Pool_yScale_List;

	int Dim;
	CImg<int> QueryImageLayer;

	int ImageHandle;
	string strFN_ImageCacheHashName;

	CZoomableImage ZoomImage;
	//CTransformableImage tfmImage;
	//CShrinkableImage srkImage;
	////C_TRSable_Image trsImage;
	////CScalableImage SourceScalableImage;
	CImagePyramidPosition Query;
	int QueryX, QueryY;
	CImagePositionFeatureExtractor*	QueryAnswerer;

protected:
	void myRelease();
public:
	CImagePyramidPositionFeatureExtractor();
	CImagePyramidPositionFeatureExtractor(CImagePositionFeatureExtractor* pInitializedIPFE, int CacheSize = 1);
	virtual ~CImagePyramidPositionFeatureExtractor();
	virtual CImagePyramidPositionFeatureExtractor& operator = (const CImagePyramidPositionFeatureExtractor& AnotherInstance);
	void InitIPFE_and_Cache(CImagePositionFeatureExtractor* pInitializedIPFE, int CacheSize = 1);
	void ClearCalculationHistory();
public:
	virtual int SetImage(const CImg<int>& imgSrcRGB, string strFN_ImageCacheHashName);
	virtual int GetFeatureDimension();
	virtual int RecomputeFeatureDimension();
	virtual double GetFeature(int FeatureIndex);
public:
	virtual void SetQuery(const CImagePyramidPosition& ImagePyramidPosition);
	virtual double GetFeature(const CImagePyramidPosition& ImagePyramidPosition, int FeatureIndex);
public:
	virtual size_t GetMemoryUsage() const;
};

